Skip to content

[12.x] Add static route cache support - backport#60287

Draft
DGarbs51 wants to merge 4 commits into
12.xfrom
add-static-route-method-for-cache-control-12.x
Draft

[12.x] Add static route cache support - backport#60287
DGarbs51 wants to merge 4 commits into
12.xfrom
add-static-route-method-for-cache-control-12.x

Conversation

@DGarbs51

@DGarbs51 DGarbs51 commented May 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Backports the Route::static() CDN-cacheable route API from the Laravel 13.x PR to Laravel 12.x.

This includes:

  • the fluent Route::static() method,
  • Illuminate\Routing\Middleware\CacheStaticResponse,
  • request-aware static-route middleware stripping,
  • final response hardening after the full HTTP middleware stack,
  • default cache.static configuration,
  • routing, middleware, kernel, and integration tests.

Backport Notes

The Laravel 13.x implementation uses Illuminate\Foundation\Http\Middleware\PreventRequestForgery in the default static-route middleware stripping list. Laravel 12.x uses Illuminate\Foundation\Http\Middleware\ValidateCsrfToken in the default web group, so this backport swaps the default to ValidateCsrfToken.

The rest of the behavior matches the 13.x PR:

  • cacheable static requests skip configured stateful middleware,
  • X-Inertia requests keep normal middleware and bypass static response mutation,
  • non-cacheable methods, non-cacheable statuses, and redirects are not made static,
  • cookies are stripped according to the route/config options,
  • Cache-Control, optional CDN-Cache-Control, and merged Vary headers are emitted,
  • the final kernel pass keeps Livewire-style global no-cache middleware from overriding static route cache headers.

Related PRs

Compatibility Verification

Verified with the Herd test app against the Laravel 12.x backport branch:

  • PHP 8.4 + Inertia 1 + Livewire 3: passed
  • PHP 8.4 + Inertia 1 + Livewire 4: passed
  • PHP 8.4 + Inertia 2 + Livewire 3: passed
  • PHP 8.4 + Inertia 2 + Livewire 4: passed
  • PHP 8.4 + Inertia 3 + Livewire 3: passed
  • PHP 8.4 + Inertia 3 + Livewire 4: passed
  • PHP 8.5 + Inertia 2 + Livewire 3: passed
  • PHP 8.5 + Inertia 2 + Livewire 4: passed
  • PHP 8.5 + Inertia 3 + Livewire 3: passed
  • PHP 8.5 + Inertia 3 + Livewire 4: passed

Inertia 1 was not installable on PHP 8.5 because inertiajs/inertia-laravel 1.x only allows PHP through 8.4.

Tests

Run with PHP 8.4 after refreshing local dependencies for the 12.x branch:

  • php84 vendor/bin/phpunit tests/Routing/RouteStaticMethodTest.php tests/Http/Middleware/CacheStaticResponseTest.php tests/Integration/Routing/RouteStaticResponseTest.php tests/Foundation/Http/KernelTest.php
  • php84 vendor/bin/phpunit tests/Routing/RoutingRouteTest.php tests/Http/Middleware/CacheTest.php
  • vendor/bin/pint config/cache.php src/Illuminate/Foundation/Http/Kernel.php src/Illuminate/Routing/Route.php src/Illuminate/Routing/Router.php src/Illuminate/Routing/Middleware/CacheStaticResponse.php tests/Foundation/Http/KernelTest.php tests/Routing/RouteStaticMethodTest.php tests/Http/Middleware/CacheStaticResponseTest.php tests/Integration/Routing/RouteStaticResponseTest.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant